//
//  GlModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum GlType: Int {
    case W = 0
    case kW
    case hp
    case ps
    case kgms
    case kcals
    case btus
    case ftlbs
    case js
    case nms
}


class GlModel: NSObject {
    let types = ["瓦","千瓦","英制马力","米制马力","公斤·米/秒","千卡/秒","英热单位/秒","英尺·磅/秒","焦耳/秒","牛顿·米/秒"]
    let signs = ["W","kW","hp","ps","kg·m/s","kcal/s","Btu/s","ft·lb/s","J/s","N·m/s"]
    
    
    func kmTall(n: Double, type: GlType, reverse: Bool = false) -> Double {
        var km3 = n
        switch type {
        case .W:
            break
        case .kW:
            km3 = reverse ? n / 0.001: n * 0.001
            break
        case .hp:
            km3 = reverse ? n / 0.001341: n * 0.001341
            break
        case .ps:
            km3 = reverse ? n / 0.0013596: n * 0.0013596
            break
        case .kgms:
            km3 = reverse ? n / 0.1019716: n * 0.1019716
            break
        case .kcals:
            km3 = reverse ? n / 0.000239: n * 0.000239
            break
        case .btus:
            km3 = reverse ? n / 0.0009478: n * 0.0009478
            break
        case .ftlbs:
            km3 = reverse ? n / 0.7375621: n * 0.7375621
            break
        case .js:
            km3 = reverse ? n / 1: n * 1
            break
        case .nms:
            km3 = reverse ? n / 1: n * 1
            break
            
        }
        return km3
    }

    
    func allChange(d: Double, type: GlType) -> [String] {
        let km = kmTall(n: d, type: type, reverse: true)
        
        
        
        return ["\(kmTall(n: km, type: .W))\(signs[0])","\(kmTall(n: km, type: .kW))\(signs[1])",
                "\(kmTall(n: km, type: .hp))\(signs[2])","\(kmTall(n: km, type: .ps))\(signs[3])",
                "\(kmTall(n: km, type: .kgms))\(signs[4])","\(kmTall(n: km, type: .kcals))\(signs[5])",
                "\(kmTall(n: km, type: .btus))\(signs[6])","\(kmTall(n: km, type: .ftlbs))\(signs[7])","\(kmTall(n: km, type: .js))\(signs[8])","\(kmTall(n: km, type: .nms))\(signs[9])"]

    }

}
